//获取应用实例
const app = getApp()

Page({
  data: {
    userId: null,
    abroadArr: [],
    pageNo: 1,
    pageSize: 20,
    lookMore: '数据加载中...',
    wh:0
  },
  todetail: function (e) {
    var item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '../abroadDetail/abroadDetail?id=' + item.id + "&abroadCountry=" + item.abroadCountry + "&abroadDateStr=" + item.abroadDateStr + "&abroadSettleDateStr=" + item.abroadSettleDateStr + "&sreturnDateStr=" + item.sreturnDateStr + "&areturnDateStr=" + item.areturnDateStr + "&abroadReason=" + item.abroadReason + "&abroadSituation=" + item.abroadSituation + "&abroadTask=" + item.abroadTask + "&remark=" + item.remark + "&action=detail"
    })
  },
  toedit: function (e) {
    var item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '../abroadDetail/abroadDetail?id=' + item.id + "&abroadCountry=" + item.abroadCountry + "&abroadDateStr=" + item.abroadDateStr + "&abroadSettleDateStr=" + item.abroadSettleDateStr + "&sreturnDateStr=" + item.sreturnDateStr + "&areturnDateStr=" + item.areturnDateStr + "&abroadReason=" + item.abroadReason + "&abroadSituation=" + item.abroadSituation + "&abroadTask=" + item.abroadTask + "&remark=" + item.remark + "&action=edit"
    })
  },
  goBack: function(){
    wx.navigateBack({
      delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
    });
  },
  toadd: function (e) {
    wx.navigateTo({
      url: '../abroadDetail/abroadDetail?action=add'
    })
  },
  onShow: function () {
    if (app.globalData.userId) {
      var that = this;
      this.setData({
        userId: app.globalData.userId
      })
      wx.request({
        url: 'https://www.xinhuo.site/api/abroad/list',
        data: {
          pageNo: this.data.pageNo,
          pageSize: this.data.pageSize,
          userId: this.data.userId
        },
        method: 'POST',
        header: {
          'Content-Type': 'application/json'
        },
        success(res) {
          if (res.data.syscode == 0) {
            if (res.data.recordList.length == that.data.pageSize) {
              that.data.lookMore = '-上滑查看更多-'
            }
            else {
              that.data.lookMore = '-没有更多内容-'
            }
            that.data.abroadArr = res.data.recordList
            that.setData({
              abroadArr: that.data.abroadArr,
              lookMore: that.data.lookMore
            })
          }
          else {
            that.setData({
              lookMore: '-暂无出国出境信息-'
            })
          }
        }
      })
    }

    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          "wh": res.windowHeight - 48 -wx.getSystemInfoSync().statusBarHeight
        })
      }
    })
  },
  loadMore() {
    var that = this;
    this.setData({
      pageNo: this.data.pageNo + 1
    });
    wx.request({
      url: 'https://www.xinhuo.site/api/abroad/list',
      data: {
        pageNo: this.data.pageNo,
        pageSize: this.data.pageSize
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        if (res.data.syscode == 0) {
          if (res.data.recordList.length == that.data.pageSize) {
            that.data.lookMore = '-上滑查看更多-'
          }
          else {
            that.data.lookMore = '-没有更多内容-'
          }
          that.data.abroadArr = that.data.abroadArr.concat(res.data.recordList)
          that.setData({
            abroadArr: that.data.abroadArr,
            lookMore: that.data.lookMore
          })
        }
        else {
          that.setData({
            lookMore: '-没有更多内容-'
          })
        }
      }
    })
  }
})
